{
数据结构 解题报告：
http://git.oschina.net/et0662/sznoi-Data_Structure
}
type 
	pnode=^node;
	node=record
		data:longint;
		next:pnode;
	end;

	queue=record
		head:pnode;
		tail:pnode;
		size:longint;
		num:longint;
	end;

	pqueue=^queue;

function initQueue():pqueue;
var
	temp:pnode;
	q:^queue;
	n:longint;
begin
	read(n);
	new(temp);
	temp^.next:=nil;
	new(q);
	q^.head:=temp;
	q^.tail:=nil;
	q^.size:=n;
	q^.num:=0;
	initQueue:=q;
end;

procedure insertQueue(q:pQueue);
var
	temp:pnode;
	n:longint;
begin
	read(n);
	if(q^.num=q^.size)then
	begin
		writeln('Full OV');
	end
	else
	begin
		inc(q^.num);
		new(temp);
		temp^.data:=n;
		temp^.next:=nil;
		if q^.tail=nil then
		begin
			q^.tail:=temp;
			q^.head^.next:=temp;
		end
		else
		begin
			q^.tail^.next:=temp;
			q^.tail:=temp;
		end;
	end;
end;

procedure outQueue(q:pQueue);
var
	temp:pnode;
begin
	if(q^.num>0)then
	begin
		dec(q^.num);
		temp:=q^.head^.next;
		q^.head^.next:=temp^.next;
		if(q^.num=0)then q^.tail:=nil;
		dispose(temp);
	end
	else
	begin
		writeln('Empty OV');
	end;
end;

procedure printQueue(q:pQueue);
var
	p:pnode;
begin
	if(q^.num=0)then
	begin
		Writeln('Empty');
	end
	else
	begin
		p:=q^.head;
		while(p^.next<>nil)do
		begin
			write(p^.next^.data,' ');
			p:=p^.next;
		end;
		writeln;
	end;
end;


var
	n:integer;
	q:pQueue;
begin
	while not eof do
	begin
		read(n);
		case n of
			1: q:=initQueue();
			2: insertQueue(q);
			3: outQueue(q);
			4: printQueue(q);
		end;
	end;
end.
